import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:xinxuan/common/dialogs/input_dialog_util.dart';
import 'package:xinxuan/common/dialogs/message_dialog.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CooperationPageController extends GetxController {
  
  final CommonPageController commonPageController = Get.find();

  /// 邀请码
  var invitationCode = ''.obs;

  /// 加入团队
  joinTeam() {
    if (commonPageController.userData.value.isInvatition == 1) {
      Get.dialog(MessageDialog(message: '您已经填写过邀请码了哦~', fontSize: 20.sp,));
      return;
    }
    Get.dialog(StatefulBuilder(
      builder: (context, setButtomSheetState) {
        return InputDialogUtil(
          title: '邀请码加入',
          hintText: '请输入邀请码',
          maxLength: 10,
          defaultValue: invitationCode.value,
          onChenge: (value) {
            invitationCode.value = value;
          },
          onSubmit: () {
            _invitations();
          }
        );
      }
    ));
  }

  /// 邀请加入
  _invitations() async {
    if (TextUtil.isEmpty(invitationCode.value)) {
      EasyLoading.showToast('请输入邀请码');
      return;
    }
    Get.back();
    bool res = await HttpUtilService.invitations(invitationCode: invitationCode.value);
    if (res) {
      invitationCode.value = '';
      EasyLoading.showToast('加入成功');
      commonPageController.checkLogin(loading: false);
    }
  }
  

}